package com.atguigu.gulimail.product.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.atguigu.gulimail.product.vo.SpuSavevo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.atguigu.gulimail.product.entity.SpuInfoEntity;
import com.atguigu.gulimail.product.service.SpuInfoService;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.Response;


/**
 * spu信息
 *
 * @author fk
 * @email hahahahha@gmail.com
 * @date 2020-08-09 23:15:28
 */
@RestController
@RequestMapping("product/spuinfo")
public class SpuInfoController {
    @Autowired
    private SpuInfoService spuInfoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    // @RequiresPermissions("product:spuinfo:list")
    public Response list (@RequestParam Map<String, Object> params) {
        PageUtils page = spuInfoService.queryPageByCondtion(params);

        return Response.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    // @RequiresPermissions("product:spuinfo:info")
    public Response info (@PathVariable("id") Long id) {
        SpuInfoEntity spuInfo = spuInfoService.getById(id);

        return Response.ok().put("spuInfo", spuInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //  @RequiresPermissions("product:spuinfo:save")
    public Response save (@RequestBody SpuSavevo spuInfo) {
        //spuInfoService.save(spuInfo);
        spuInfoService.saveSpuInfo(spuInfo);
        return Response.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    // @RequiresPermissions("product:spuinfo:update")
    public Response update (@RequestBody SpuInfoEntity spuInfo) {
        spuInfoService.updateById(spuInfo);

        return Response.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    // @RequiresPermissions("product:spuinfo:delete")
    public Response delete (@RequestBody Long[] ids) {
        spuInfoService.removeByIds(Arrays.asList(ids));

        return Response.ok();
    }

    @PostMapping("/{spuId}/up")
    public Response spuUp (@PathVariable("spuId") Long spuId) {
        spuInfoService.up(spuId);

        return Response.ok();
    }

}
